from flask import Blueprint
from .base import BaseRoute


class UserRoute(BaseRoute):
    """用户路由类"""
    def __init__(self):
        super().__init__('user', '/api/users')
    
    def register_routes(self, container):
        """注册用户相关路由"""
        user_controller = self.get_controller(container, 'user')
        
        @self.bp.route('', methods=['GET'])
        def get_users():
            return user_controller.get_users()
        
        @self.bp.route('/<int:user_id>', methods=['GET'])
        def get_user(user_id):
            return user_controller.get_user(user_id)
        
        @self.bp.route('', methods=['POST'])
        def create_user():
            return user_controller.create_user()
        
        @self.bp.route('/<int:user_id>', methods=['PUT'])
        def update_user(user_id):
            return user_controller.update_user(user_id)
        
        @self.bp.route('/<int:user_id>', methods=['DELETE'])
        def delete_user(user_id):
            return user_controller.delete_user(user_id)
            
        @self.bp.route('/login', methods=['POST'])
        def login():
            return user_controller.login()
            
        @self.bp.route('/register', methods=['POST'])
        def register():
            return user_controller.register()
            
        @self.bp.route('/logout', methods=['POST'])
        def logout():
            return user_controller.logout()
            
        @self.bp.route('/check-login', methods=['GET'])
        def check_login():
            return user_controller.check_login_status()
            
        @self.bp.route('/<int:user_id>/change-password', methods=['PUT'])
        def change_password(user_id):
            return user_controller.change_password(user_id)
        
        return self.bp